package demo06.ThreadSafe;

public class RunnableImpl implements Runnable {
    private int ticket=100;
    @Override
    public void run() {
        while (true){
            if(ticket>0){
                //提高出错概率，小睡一会
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"正在售第"+ticket+"张票");
                ticket--;
            }
            else {
                return;
            }
        }
    }
}
